package com.bigShen.pattern.template.dao;


import com.bigShen.pattern.template.Entity.User;
import com.bigShen.pattern.template.JDBCTemplate;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * @author: lei.shen
 * @date: 2018/10/6
 */
public class UserDAO {

        private JDBCTemplate jdbcTemplate;

        public List<?> query() {
            String sql = "select * from t_user";
            return jdbcTemplate.executeQuery(sql, new RowMapper<User>() {

                public User mapRow(ResultSet resultSet, int i) throws SQLException {
                    User user = new User();
                    user.setUserName(resultSet.getString("username"));
                    user.setPassword(resultSet.getString("password"));
                    user.setAge(resultSet.getInt("age"));
                    user.setAddress(resultSet.getString("address"));
                    return user;
                }
            }, null);
        }

}
